﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Example12.aspx.cs" Inherits="Chapter30.Example12" %>

<!DOCTYPE html>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>代码清单 30-12 使用键盘焦点事件</title>
    <meta name="author" content="Adam Freeman" />
    <meta name="description" content="A simple example" />
    <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
    <style title="cor styles">
        p {
            background: gray;
            color: white;
            padding: 10px;
            margin: 5px;
            border: thin solid black;
        }
    </style>
</head>
<body>
    <form>
        <p>
            <label for="fave">
                Fruit:
                <input autofocus="autofocus" id="fave" name="fave" />
            </label>
        </p>
        <p>
            <label for="name">
                Name:
                <input autofocus="autofocus" id="name" name="name" />
            </label>
        </p>
        <button type="submit">Submit Vote</button>
        <button type="reset">Reset</button>
    </form>
    <script>
        var inputElems = document.getElementsByTagName("input");
        for (var i = 0; i < inputElems.length; i++) {
            inputElems[i].onfocus = handleFocusEvent;
            inputElems[i].onblur = handleFocusEvent;
        }

        function handleFocusEvent(e) {
            if (e.type == "focus") {
                e.target.style.background = "lightgray";
                e.target.style.border = "thick double red";
            } else {
                e.target.style.removeProperty("background-color");
                e.target.style.removeProperty("border");
            }
        }
    </script>
</body>
</html>
